package com.demo.springbootquartz.task;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail myTask() {
        return JobBuilder.newJob(MyTask.class).withIdentity("myTask")
                .storeDurably().build();
    }

    @Bean
    public Trigger myTaskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
                .cronSchedule("0/3 * * * * ? *");
        return TriggerBuilder.newTrigger().forJob(myTask())
                .withIdentity("myTask")
                .withSchedule(scheduleBuilder).build();
    }
}
